<script lang="ts" setup>
import { get, post, message, loadFile } from '@/utils'
import { FormInstance } from '@arco-design/web-vue'
const props = defineProps<{
  show: boolean
  id: number | string
}>()
const emit = defineEmits(['update:show', 'reset', 'confirm'])
const formRef = ref() as Ref<FormInstance>
const detail = reactive({
  account: '',
  avatar: '',
  bindingTime: '',
  birthday: '',
  chain: '',
  createTime: '',
  exp: 0,
  grandpaId: 0,
  integral: 0,
  isPlace: 0,
  level: 0,
  mobile: '',
  money: 0,
  nickName: '',
  parentId: 0,
  sex: 0,
  status: 0,
  tagId: '',
  updateTime: '',
  version: 0,
})
const submit = done => {
  formRef.value.validate(err => {
    if (!err) {
      const query = Object.assign({}, detail)
      post(
        { url: '/server-user/sys-seller/user/update', data: query },
        ({ code, msg }) => {
          message({
            type: code == 200 ? 'success' : 'error',
            content: msg,
          })
          emit('update:show', false)
          emit('confirm')
          done(true)
        },
        () => done(false)
      )
    } else done(false)
  })
}
const getInfo = () => {
  get({ url: '/server-user/sys-seller/user/info', data: { id: props.id } }, ({ data }) => {
    Object.assign(detail, data)
  })
}
onMounted(() => {
  if (props.id) getInfo()
})
</script>
<template>
  <CDrawer v-model:visible="props.show" @before-ok="submit" :mask-closable="false" width="1000px" :title="props.id ? '编辑' : '新建'" @cancel="emit('update:show', false)">
    <a-form :model="detail" ref="formRef" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 16 }">
      <div class="grid-2">
        <a-form-item label="用户昵称" field="nickName" :rules="[{ required: true, message: '请输入用户昵称' }]" :validate-trigger="['change', 'blur']">
          <a-input v-model="detail.nickName" placeholder="请输入用户昵称" />
        </a-form-item>
        <a-form-item label="手机号码" field="mobile" :rules="[{ required: true, message: '请输入手机号码' }]" :validate-trigger="['change', 'blur']">
          <a-input v-model="detail.mobile" placeholder="请输入手机号码" />
        </a-form-item>
      </div>
    </a-form>
  </CDrawer>
</template>
<style lang="less" scoped></style>
